Page({
  data: {
    tabIndex: 0, // 0 通知 1 聊天
    notices: [
      { id: 1, icon: '🔔', title: '系统消息', sub: '系统更新通知', count: 1, type: 'system' },
      { id: 2, icon: '💊', title: '健康提醒', sub: '用药提醒', count: 4, type: 'health' },
      { id: 3, icon: '💬', title: '评论&回复', sub: '有人评论了你', count: 3, type: 'comment' },
      { id: 4, icon: '👥', title: '关注', sub: '新的关注', count: 7, type: 'follow' },
      { id: 5, icon: '❤️', title: '赞和收藏', sub: '有人给你点赞', count: 4, type: 'like' },
      { id: 6, icon: '🧾', title: '订单消息', sub: '订单已完成', count: 1, type: 'order' }
    ],
    chats: [
      { id: 100, avatar: 'https://dummyimage.com/120x120/cccccc/888888.png&text=U1', name: '社区小助手', last: '您好，活动开始时间提醒', time: '昨天', unread: 2 },
      { id: 101, avatar: 'https://dummyimage.com/120x120/cccccc/888888.png&text=U2', name: '邻里王阿姨', last: '一起散步吗？', time: '周一', unread: 0 }
    ]
  },

  onShow() {
    if (this.getTabBar && this.getTabBar()) {
      this.getTabBar().setData({ selected: 2 });
    }
  },

  onTabChange(e) {
    const idx = e.currentTarget.dataset.index;
    this.setData({ tabIndex: idx });
  },

  onMarkAllRead() {
    if (this.data.tabIndex === 0) {
      const notices = this.data.notices.map(n => ({ ...n, count: 0 }));
      this.setData({ notices });
    } else {
      const chats = this.data.chats.map(c => ({ ...c, unread: 0 }));
      this.setData({ chats });
    }
    wx.showToast({ title: '已全部已读', icon: 'none' });
  },

  onNoticeTap(e) {
    const item = e.currentTarget.dataset.item;
    wx.showToast({ title: `${item.title}`, icon: 'none' });
  },

  onChatTap(e) {
    const item = e.currentTarget.dataset.item;
    wx.showToast({ title: `进入与${item.name}的聊天`, icon: 'none' });
  }
});
